from __future__ import division
from visual import *

import random
border=10
decoration=60

def RR():
  return (round(random.uniform(0,1),2),round(random.uniform(0,1),2),round(random.uniform(0,1),2))

#rotation frame
mainwindow=display(title='Main Window',x=0, y=0, width=600, height=600, show_rendertime=true)
figure = frame()
box(frame=figure, pos=(0,0,0),length=4,height=4, width=4,  opacity=0.6)
for i in (1,0,0),(0,1,0),(0,0,1): #faccio tre cilindri con queste coordinate d'asse
	 cylinder(frame=figure, pos=(0,0,0),axis=i, radius=0.1, length=2.5)


#coord frame
coordwindow=display(title='Coord',x=mainwindow.width+border, y=0, width=200, height=200)
coord  = frame()
for i in zip([(1,0,0),(0,1,0),(0,0,1)],[color.red,color.blue,color.yellow],["X","Y","Z"]): #passo sia le coordinate sia il colori alle frecce e alle label
	arrow(frame=coord, pos=(0,0,0), axis=i[0], length=2.5, shaftwidth=0.1, color=i[1])
	label(frame=coord, pos=i[0], axis=(1,0,0), height=8, text=i[2], box=false)

#acell frame
accwindow=display(title='Acc',x=mainwindow.width+border, y=coordwindow.height+decoration, width=200, height=200)
acc = frame()
accx=arrow(frame=acc, pos=(-(accwindow.x/2),0,0), axis=(1,0,0), color=color.red)
accy=arrow(frame=acc, pos=(-(accwindow.x/2),30,0),axis=(1,0,0), color=color.blue)

#info
infowindow=display(title='Info',x=mainwindow.width+border, y=coordwindow.height+accwindow.height+decoration*2, width=200, height=200)
infotext=label(pos=(0,0,0), height=16, text='', box=false)

while True:
	rate(16)
	rnd=RR()
	accx.length=rnd[0]*180.
	accy.length=rnd[1]*180.
	coord.rotate( angle=pi/100., axis=rnd)
	figure.rotate(angle=pi/100., axis=rnd)
	infotext.text="Giroscopio"+'\n'+"("+str(rnd[0])+","+str(rnd[1])+","+str(rnd[2])+")"+"\nAcc\n"+"["+str(accx.length)+","+str(accy.length)+"]"
	

